Option Explicit

If "CSCRIPT.EXE" <> UCase( Right( WScript.Fullname, 11 ) ) Then
    WScript.Echo "This program requires command line VBScript interpreter. Usage: cscript dom.vbs"
    WScript.Quit 1
End If

Dim Doc
Set Doc = CreateObject("HL7SDK.Cda.ClinicalDocument")
Doc.Load "..\SampleCDADocument.xml"


Doc.Lazy = False
TraverseCDAItem Doc, 0

Sub TraverseCDAItem(Element, Level)
    Dim Indent
    Dim I
    For I = 0 to Level
      Indent = Indent & "  "
    Next
	If TypeName(Element) = "Section" Then
	    If Element.Title is Nothing Then
	        WScript.Echo "Found section"
	    Else
	    	WScript.Echo "Found section: " & Element.Title.Text
	    End If
	    Dim TemplateId
	    For Each TemplateId in Element.TemplateId
	    	WScript.Echo "  TemplateId: " & TemplateId.Root 
	    Next
	End If	
	Dim ChildObject
	For Each ChildObject In Element.ChildObjects
		TraverseCDAItem ChildObject, Level + 1
	Next
	
End Sub